package com.starfactory.customer;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 用户微服务启动类
 *
 */
@Slf4j
@EnableFeignClients
@EnableDiscoveryClient
@EnableTransactionManagement
@EnableConfigurationProperties
@SpringBootApplication(scanBasePackages = {"com.starfactory.customer", "com.starfactory.common"})
@MapperScan(basePackages = "com.starfactory.customer.table")
public class Application {

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext;
        try {
            applicationContext = SpringApplication.run(Application.class, args);

            System.out.println("Server startup done.");
        } catch (Exception e) {
            log.error("服务启动报错", e);
            return;
        }

        Environment env = applicationContext.getEnvironment();
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        if (StringUtils.isEmpty(path)) {
            path = "";
        }
        System.out.println("\n----------------------------------------------------------\n\t" +
                "Application is running! Access URLs:\n\t" +
                "Ping: \t\thttp://localhost:" + port + path + "/ping.html\n\t" +
                "----------------------------------------------------------");
    }
}
